#include "BaseSprite.h"
#include "SpriteHelper.h"
USING_NS_CC;

BaseSprite::BaseSprite(void)
{
	this->actionCache=new CCDictionary();
	this->spriteTag=SpriteTag::null;
}


BaseSprite::~BaseSprite(void)
{
	this->actionCache=NULL;
}

void BaseSprite::InitFrameSet( int startFrameIndex, int frameCount, char *frameFormat, const char *plistFile,SpriteAction action)
{
	CCAssert(spriteTag!=SpriteTag::null,"sprite tag not init.");

	SpriteHelper::InitFrameSet(startFrameIndex,
								frameCount,
								frameFormat,
								plistFile,
								action,
								this->spriteTag);
}

void BaseSprite::SetCurrentAction(SpriteAction action )
{
	BaseSprite::SetCurrentAction(action,NULL);
}

void BaseSprite::SetCurrentAction(SpriteAction action,CCCallFuncN * callback)
{
	CCAssert(spriteTag!=SpriteTag::null,"sprite tag not init.");

	CCAction * subAction=NULL;
	if(action!=SpriteAction::Dead&& action!=SpriteAction::EffectAction)
	{
		subAction=SpriteHelper::SetCurrentAction(this,action,this->spriteTag);		
	}
	else
	{
		subAction=SpriteHelper::SetCurrentActionNoRepeat(this,action,this->spriteTag,callback);
	}
	actionCache->setObject(subAction,action);
	currentAction=action;
}

void BaseSprite::draw()
{
	/*for (CCSprite *obj in [self children]) if ([obj isKindOfClass:[CCSprite class]])
	{*/

		//CCPoint esquina1 = ccp(this->getPositionX()-this->getContentSize().width/2,this->getPositionY()-this->getContentSize().height/2);
		//CCPoint esquina2 = ccpAdd(esquina1, ccp(this->getContentSize().width,0));
		//CCPoint esquina3 = ccpAdd(esquina1, ccp(this->getContentSize().width,this->getContentSize().height));
		//CCPoint esquina4 = ccpAdd(esquina1, ccp(0,this->getContentSize().height));

		//glColor4ub(255, 255, 255, 255);
		//glLineWidth(2);
		////glEnable(GL_LINE_SMOOTH);

		//ccDrawLine(esquina1, esquina2);
		//ccDrawLine(esquina2, esquina3);
		//ccDrawLine(esquina3, esquina4);
		//ccDrawLine(esquina4, esquina1);
	//ccColor4F color={100/255,100/255,100/255,100/255};
	//ccDrawSolidRect(this->getPosition(),ccpAdd(this->getPosition(),ccp(10,10)),(ccColor4F){100/255,100/255,100/255,100/255}),
		CCSprite::draw();
	//}
}

